<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>壹码当先 - 上传作品</title>
    <link href="/pages/css/kefu.css" rel="stylesheet">
    <script type="text/javascript" src="/pages/js/jquery001.js"></script>
    <!-- Chosen CSS -->
    <link href="/pages/css/login-register.css" rel="stylesheet">
    <!-- Pretty Photo CSS -->
    <link href="/pages/css/prettyPhoto.css" rel="stylesheet">
    <!-- Chosen CSS -->
    <link href="/pages/css/chosen.min.css" rel="stylesheet">
    <!-- Chosen CSS -->
    <link href="/pages/css/dashboard.css" rel="stylesheet">
    <!-- Custom Main StyleSheet CSS -->
    <link href="/pages/style.css" rel="stylesheet">
    <!-- Color CSS -->
    <link href="/pages/css/color.css" rel="stylesheet">
    <link href="/pages/css/color-2.css" rel="stylesheet">
    <!-- Responsive CSS -->
    <link href="/pages/css/responsive.css" rel="stylesheet">

    <script type="text/javascript" src="/pages/js/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            /**
             * 查看用户信息
             */
            $.post("/user/detail", {}, function (result) {
                if (result.status === 1) {
                    var data = result.data;
                    $("#header").html('<img id="header" src="' + data.header + '">');
                    $("#nickName").html(data.nickName);
                    $("#studentId").html(data.studentId);
                } else {
                    alert("用户未登录");
                    window.location.href = "/pages/index.html";
                }
            });


            /**
             * 图片上传
             */
            $("#uploadImage").click(function () {
                var formData = new FormData();
                formData.append('upload', $('#imageFile')[0].files[0]);
                $.ajax({
                    url: '/upload/image',
                    type: 'POST',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false
                }).done(function (res) {
                    if (res.status === 1) {
                        $("#imageDiv").html('<img src="' + res.data + '">');
                        $("#sbimage").val(JSON.stringify(res.data));
                        alert("上传成功");
                    }
                    else {
                        alert("图片上传失败");
                    }
                }).fail(function (res) {
                    alert("图片上传失败");
                });
            });


            /**
             * sb2文件上传
             */
            $("#uploadSb2").click(function () {
                var formData = new FormData();
                formData.append('upload', $('#sb2File')[0].files[0]);
                $.ajax({
                    url: '/upload/sb2',
                    type: 'POST',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false
                }).done(function (res) {
                    if (res.status === 1) {
                        $("#sburl").val(JSON.stringify(res.data));
                        alert("上传成功");
                    }
                    else {
                        alert("文件上传失败");
                    }
                }).fail(function (res) {
                    alert("文件上传失败");
                });
            });

            //保存
            $("#productBtn").click(function () {
                var url = "/user/product/save";
                var showProduct = 0;
                if ($("#showProduct").prop('checked')) {
                    showProduct = 1;
                }
                var id = $("#productId").val(),
                        name = $("#productName").val(),
                        author = $("#author").val(),
                        introduction = $("#introduction").val(),
                        sbimage = $("#sbimage").val(),
                        sburl = $("#sburl").val(),
                        showOrder = $("#showOrder").val();
                $.post(url, {
                    id: id,
                    name: name,
                    author: author,
                    introduction: introduction,
                    sbimage: sbimage,
                    sburl: sburl,
                    showProduct: showProduct,
                    showOrder: showOrder
                }, function (result) {
                    if (result.status === 1) {
                        alert("保存成功！");
                        window.location.href = "/pages/ymdx/users/myworks.html";
                    }
                    else {
                        alert("保存失败！" + result.message);
                    }
                })
            });
        })
    </script>

</head>

<body onload="IFrameResize()">

<script type="text/javascript">
    function IFrameResize() {
        //alert(this.document.body.scrollHeight); //弹出当前页面的高度
        var obj = parent.document.getElementById("iframe1");  //取得父页面IFrame对象
        //alert(obj.height); //弹出父页面中IFrame中设置的高度
        obj.height = this.document.body.scrollHeight;  //调整父页面中IFrame的高度为此页面的高度
    }
</script>

<!--Sub Banner Wrap Start -->
<div class="gt_sub_banner_bg default_width">
    <div class="container">
        <div class="gt_sub_banner_hdg  default_width">
            <h2>上传作品</h2>
            <h6>壹码当先&nbsp;·&nbsp;让更多的孩子爱上编程</h6>
        </div>
    </div>
</div>
<!--Sub Banner Wrap End -->
<!--Breadcrumb Wrap End -->
<div class="gt_breadcrumb_bg default_width">
    <div class="container">
        <div class="gt_breadcrumb_wrap default_width">
            <ul>
                <li><a href="/pages/index.html">首页</a></li>
                <li><a href="myworks.html">我的作品</a></li>
                <li><a href="#">上传更多作品</a></li>
            </ul>
        </div>
    </div>
</div>
<!--Breadcrumb Wrap End -->

<!--Main Content Wrap Start-->
<div class="gt_content_wrap">
    <!--Classes Wrap Start-->
    <section class="gt_courses_bg">
        <div class="container">

            <!-- Dashboard Side Bar Wrap Start -->
            <div class="col-md-4">
                <div class="gt-user-sidebar">
                    <div class="gt_d_author_wrap">
                        <div class="gt_d_author_pic">
                            <figure id="header">
                                <!--用户头像-->
                            </figure>
                        </div>
                        <div class="gt_d_author_pic_des">
                            <h5 id="nickName"></h5>
                            <span class="gt_hdg_span"></span>
                            <p>学员号</p>
                            <label id="studentId"></label>
                        </div>
                    </div>
                    <div class="gt-usser-account-list">
                        <ul>
                            <li><a href="/pages/ymdx/users/information.html"><i class="icon-book gt-color"></i>个人信息</a>
                            </li>
                            <li><a href="/pages/ymdx/users/myworks.html"><i class="icon-clock-1 gt-color"></i>我的作品</a>
                            </li>
                            <li><a href="/pages/ymdx/users/editpwd.html"><i class="icon-three gt-color"></i>修改密码</a>
                            </li>
                        </ul>
                        <a href="#" class="gt-logout"><i class="icon-arrows-2 gt-color"></i>退出登录</a>
                    </div>
                </div>
            </div>
            <!-- Dashboard Side Bar Wrap End -->


            <!--Classes List Wrap Start-->
            <div class="col-md-8">
                <div class="gt_d_classes_wrap default_width mb20">
                    <h4 class="gt_d_title">上传作品</h4>
                    <div class="gt_d_profile_setting default_width">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="gt_privacy_field default_width mb20">
                                    <input id="productName" class="c_ph" type="text" placeholder="作品名：">
                                </div>
                            </div>
                            <div class="col-md-12">
                                <div class="gt_privacy_field default_width mb20">
                                    <textarea id="introduction" class="c_ph" placeholder="作品介绍："></textarea>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-5">
                            <h4 class="gt_d_title">上传封面图</h4>
                            <input id="imageFile" type="file"/>
                            <input id="sbimage" type="text" hidden>
                            <button id="uploadImage" type="button"
                                    style="height: 25px; margin-top: 10px; margin-bottom: 10px; width: 80px; background-color: #E1E1E1;">
                                提交
                            </button>
                            <div class="gt_d_upload_photo default_width">
                                <div class="gt_d_upload_area default_width" id="imageDiv">
                                </div>
                                <span>最大图片尺寸: <em>10.00 MB</em></span>
                                <span>规模：<em>370x377</em></span>
                                <span>支持格式：<em>JPG,JPEG,PNG,GIF</em></span>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-5">
                            <h4 class="gt_d_title">上传作品</h4>
                            <input id="sb2File"  type="file"/>
                            <input id="sburl" type="text" hidden>
                            <button id="uploadSb2" type="button"
                                    style="height: 25px; margin-top: 10px; margin-bottom: 10px; width: 80px; background-color: #E1E1E1;">
                                提交
                            </button>
                        </div>
                    </div>

                    <div class="gt_d_scl_setting default_width">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="gt_privacy_field default_width">
                                    <input id="productBtn" type="submit" value="保存" style="background-color: #0177b5;">
                                </div>
                            </div>
                        </div>
                    </div>


                </div>
            </div>
            <!--Classes List Wrap End-->
        </div>
    </section>
    <!--Classes Wrap End-->
</div>
<!--Main Content Wrap End-->

<!--Jquery Library-->
<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
<!--Bootstrap core JavaScript-->
<script src="http://www.jq22.com/jquery/bootstrap-3.3.4.js"></script>
<!--Chosen JavaScript-->
<script src="/pages/js/chosen.jquery.min.js"></script>
<!--Custom JavaScript-->
<script src="/pages/js/custom.js"></script>

</body>
</html>
